class Transaction < ActiveRecord::Base
  attr_accessible :amount, :is_credit, :on_date, :person_id, :reference_id, :reference_type

  belongs_to :reference, :polymorphic => true
  belongs_to :person

  validates :amount,:numericality => { :greater_than => 0}
  validates :on_date, :presence => true

  after_initialize :set_todays_date_as_transaction_date

  def set_todays_date_as_transaction_date()
    self.on_date ||= Date.today if new_record?
  end
end
